/******************************************************************************
* This file is part of is32p218 platform,
* Copyright (c) 2009 HangZhou InfoStrong CO.,LTD. All rights reserved.
* This software may only be used under the terms of a valid, current,
* end user license from InfoStrong.
* Nothing else gives you the right to use this software.   
*
* Name:   os_tmr.h
* Desc:   isOS timer header file
* Author: Jerry
* Date:   2009-12-1
* Note:   
* History:
*
******************************************************************************/
#include "isOS.h"
#include "os_cfg.h"

#ifndef __OS_TMR_H__
#define __OS_TMR_H__

#if (OS_TMR_EN ==1 )

#ifdef __cplusplus
extern "C" {
#endif
/*-----------------------------------------------------------
 * MACROS AND DEFINITIONS
 *----------------------------------------------------------*/
#define TMR_FLG_SIGNAL		0x01
#define TMR_1S_FLG_SIGNAL	0x02

#define  TMR_OPT_NONE			0u    /* < No option selected */
#define  TMR_OPT_ONE_TIME		1u    /* < Timer will enter to stop state when it expires    */
#define  TMR_OPT_PERIODIC		2u    /* < Timer will automatically restart when it expires    */

#define  TMR_STATE_UNUSED		0u
#define  TMR_STATE_STOPPED		1u
#define  TMR_STATE_RUNNING		2u


#define TMR_CNT_FOREVER			0u
typedef  void (*isOS_TMR_CALLBACK)(void *pvArg);

/*
 * Definition of the Mbox used by the scheduler.
 * Based on FIFO
 */
typedef struct _isOS_TMR
{
	struct _isOS_TMR *pxNext;
	isOS_TMR_CALLBACK pxTmrCallBack;	/* < Timer callback function */
	void *pvArg;					/* < Timer void argument */	
	isOS_U32 xCntTick;				/* < Count time */
	isOS_U32 xCntTickLoad;			/* < Count time load value */
	isOS_U8 xTmrID;					/* < Timer ID */
	isOS_U8 xTmrState;				/* < The state of the timer, according to TMR_STATE_xxx macro*/
	isOS_U8 xTmrOpt;				/* < Timer Option */
#if OS_TMR_NAME_EN
	isOS_S8 *pname;
#endif
} isOS_TMR;

/*-----------------------------------------------------------*/
 
typedef isOS_TMR * xTmrHandle;

/*-------------------Timer Functions Declaration--------------------------*/

isOS_S32 isOS_TmrCreate( isOS_TMR *pxTmr, isOS_U32 xExpireTick, isOS_TMR_CALLBACK pxTmrCallback, \
							void *pvTmrArg, isOS_S8 *pname );
isOS_S32 isOS_TmrCreateEx( isOS_TMR *pxTmr, isOS_U32 xExpireTick, isOS_TMR_CALLBACK pxTmrCallback, \
							void *pvTmrArg, isOS_S8 *pname, isOS_U8 Opt );
isOS_S32 isOS_TmrSetExpireTick( xTmrHandle pxTmr, isOS_U32 xNewExpire );

isOS_S32 isOS_TmrReset( xTmrHandle pxTmr, isOS_U32 xExpireTick, 
						isOS_TMR_CALLBACK pxTmrCallback, void *pvTmrArg );

isOS_S32 isOS_TmrStart( xTmrHandle pxTmr );
isOS_S32 isOS_TmrStop( xTmrHandle pxTmr );
void isOS_TmrDelete( xTmrHandle pxTmr );
isOS_BOOL isOS_TmrRunNone( void );
void isOS_TmrInit( void );
void isOS_TmrCheck( isOS_U32 curOSTick );

#ifdef __cplusplus
}
#endif

#endif // end #if (OS_FLG_EN ==1 )

#endif /* __OS_TMR_H__ */




